<?php

namespace App\Admin\Extensions\Table;

use App\Admin\Repositories\Worker;
use Dcat\Admin\Grid;
use Dcat\Admin\Grid\LazyRenderable;
use Dcat\Admin\Traits\LazyWidget;

class WorkerTable extends LazyRenderable
{
    use LazyWidget;

    public function grid(): Grid
    {
        // 获取外部传递的参数
        $shop_id = $this->shop_id;
        return Grid::make(new Worker(['user']), function (Grid $grid) use ($shop_id) {
            $grid->disableCreateButton();
            $grid->disableBatchActions();
            $grid->disableRowSelector();
            $grid->disableActions();
            $grid->model()->where("shop_id",$shop_id);
            $grid->column('id')->sortable();
            $grid->column('user_id');
            $grid->column('user.nickname','用户昵称');
            $grid->column('image','图片')->image(null,40,40);
            $grid->column('name','员工名称');
            $grid->column('phone','员工电话');
            $grid->column('money');
            $grid->column('used_money');
            $grid->column('status')->using(['正常','隐藏'])->label(['info','default']);
            $grid->column('created_at');
//            $grid->column('updated_at')->sortable();

            $grid->filter(function (Grid\Filter $filter) {
                $filter->panel();
                $filter->expand(false);
                $filter->equal('id')->width(3);
                $filter->like('user.nickname','用户昵称')->width(3);
                $filter->like('name')->width(3);
                $filter->like('phone','手机号')->width(3);
                $filter->equal("status","状态")->select(['正常','隐藏'])->width(3);
            });
            $grid->paginate(8);
        });
    }


}
